class DelSpec extends Mutator Config;
var config int maxSpec;

event PreBeginPlay()
{
	SetTimer(30,true);
}

static function FillPlayInfo(PlayInfo PlayInfo)
{
	Super.FillPlayInfo(PlayInfo);
	PlayInfo.AddSetting(default.RulesGroup, "maxSpec", "TmpMax Spectators", 0, 0, "text");
}

static function string GetDescriptionText(string PropName)
{
	switch (PropName)
	{
		case "maxSpec":	            return "TmpMax Spectators";
	}
}

function Timer()
{

	local Controller C;
	//local KFPlayerController KFPC;
	local int spectatorCount;
	spectatorCount=0;
	if(SRGameType(Level.Game).WaveNum<1 && !SRGameType(Level.Game).bWaveInProgress) return;
	for (C = Level.ControllerList; C != None; C = C.NextController)
	{
		if(	C.IsA('PlayerController') && 
			!C.PlayerReplicationInfo.bBot &&
			C.PlayerReplicationInfo.bOnlySpectator &&
			//!C.PlayerReplicationInfo.bAdmin &&
			C.PlayerReplicationInfo.PlayerID>0)
		{
			//Log("Spec__"@C.PlayerReplicationInfo.PlayerName);
			spectatorCount++;
		}
	}
	//Log("InfoSpec"@Level.Game.NumPlayers@Level.Game.MaxPlayers@spectatorCount);
	if(spectatorCount>=maxSpec)
	{
		for (C = Level.ControllerList; C != None; C = C.NextController)
		{
			if(	C.IsA('PlayerController') && 
				!C.PlayerReplicationInfo.bBot &&
				C.PlayerReplicationInfo.bOnlySpectator &&
				!C.PlayerReplicationInfo.bAdmin &&
				C.PlayerReplicationInfo.PlayerID>0)
			{
				PlayerController(C).BecomeActivePlayer();
				return;
			}
		}
	}
	//Destroy();
}

defaultproperties
{
     maxSpec=2
     bAddToServerPackages=True
     GroupName="DelSpec"
     FriendlyName="DelSpec"
     Description="Removes second spectator."
}
